package com.kxf.zxingmini;

import android.Manifest;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.google.zxing.Result;
import com.kxf.zxingmini.databinding.ActivityMainBinding;
import com.kxf.zxingmini.interfaces.ScanViewCallBack;
import com.tbruyelle.rxpermissions.RxPermissions;

import rx.functions.Action1;

/**
 * 全屏的扫码
 */
public class MainActivity extends BaseActivity<ActivityMainBinding> {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_main);

        viewBinding.myScanView.setScanViewCallBack(new ScanViewCallBack() {
            @Override
            public void scaning(Bitmap bitmap) {
                System.out.println("正在解码===>>>" + bitmap);
                viewBinding.imageView.setImageBitmap(bitmap);
            }

            @Override
            public void scanSuccess(Bitmap bitmap, Result result) {
                viewBinding.myScanView.stopScan();
                viewBinding.text.setText("扫码结果：" + result.getText());
                viewBinding.findView.setActive(false);
                viewBinding.findView.setVisibility(View.GONE);
            }
        });

        Log.d("kxf", "分别申请多个权限========>");
        //分别申请多个权限
        RxPermissions.getInstance(MainActivity.this)
                //分别申请多个权限时，使用requestEach
                .request(Manifest.permission.CAMERA)
                .subscribe(new Action1<Boolean>() {
                    @Override
                    public void call(Boolean aBoolean) {
                        Log.d("MainActivity", "permission=" + aBoolean);
                        if (aBoolean){
                        }else {
                            finish();
                        }
                    }
                });
    }
}
